package com.vodone.v1pin.userInfo.delegate
{
	import com.vodone.v1pin.core.utils.GoodsUtil;
	import com.vodone.v1pin.userInfo.vo.StoreVO;

	public class LoveUtil
	{
		public static function getLoveListFromObj(obj:Object):Array
		{
			var list:Array = [];
			if(obj && obj is Array)
			{
				var arr:Array = obj as Array;
				if(arr && arr.length > 0)
				{
					for(var i:int = 0; i< arr.length ; i++)
					{
						list.push(getLoveItem(arr[i]));
					}
				}
			}
			return list;
		}
		public static function getLoveItem(obj:Object):StoreVO
		{
			var item:StoreVO = new StoreVO();
			if(obj)
			{
				if(obj.hasOwnProperty("cname"))
				{
					item.cname = obj["cname"];
				}
				if(obj.hasOwnProperty("ename"))
				{
					item.ename = obj["ename"];
				}
				if(obj.hasOwnProperty("id"))
				{
					item.id = obj["id"];
				}
				if(obj.hasOwnProperty("navURL"))
				{
					item.navURL = obj["navURL"];
				}
				if(obj.hasOwnProperty("price"))
				{
					item.price = obj["price"];
				}
				if(obj.hasOwnProperty("url"))
				{
					item.url = GoodsUtil.get120PicUrl(obj["url"]);
				}
				if(obj.hasOwnProperty("v1pinPrice"))
				{
					item.v1pinPrice = obj["v1pinPrice"];
				}
				if(obj.hasOwnProperty("productcode"))
				{
					item.productcode = obj["productcode"];
				}
			}
			return item;
		}
		
		public static function getFormatData(list:Array , count:int ):Array
		{
			var result:Array = [];
			if(list && list.length > 0 && count > 0)
			{
				var dataLen:int = list.length;
				var len:int = dataLen / count ;
				if( list.length % count != 0 )
				{
					len++;
				}
				for(var i:int = 0 ;i < len ; i++)
				{
					var obj:Array = [];
					for(var j:int = 0 ; j < count ; j++)
					{
						if( (i * count + j) < dataLen)
						{
							obj.push(list[i * count + j]);
						}
						else
						{
							obj.push( new StoreVO() );
						}
					}
					result.push(obj);
				}
			}
			return result;
		}
		
	}
}